<?php 
$dsn = "mysql:host=localhost;dbname=hdc50";
$username = "root";
$password = "";
try {
	$pdo = new Pdo($dsn,$username,$password);
} catch (PDOException $e) {
	die($e->getMessage());
}

$pdo = query("set names utf8");
$data = ['sname'=>'小鹏','sex'=>1];
try {
	$sql = "insert into stu(sname,sex) values(?,?)";

	$state = $pdo->prepare($sql);
	$id=0;
	foreach ($data as $key => $value) {
		print_r($data);exit;
		$style = is_numeric($value)?PDO::PARAM_INT:PDO::PARAM_STR;
		$$key=$value;
		$state->bindParam(++$id,$$key,$style);
	}
	$row = $state->execute();
	print_r($row);
} catch (PDOException $e) {
	$e->getMessage();
}